CommonGisBonita = {
		resetCombo:function(layerid){
			var index = 0;
			for(var i=0;i<vectorArray.length;i++){
				var id = vectorArray[i].LayerId;
				if(vectorArray[i].SearchAttr&&id==layerid){
					index = vectorArray[i].IndexLayer;
					break;
				}
			}
			$("#select_Tool_cboLayers_Query option").each(function(){
				$(this).show();
			});
			$("#select_Tool_cboLayers_Query option").each(function(){
				var value = $(this).val();
				if(value!=index)$(this).hide();
			});
			$("#select_Tool_cboLayers_Query").uniform();
		},
		getColumnKey:function(layerid){
			//arrField_Alias
			arrField_Alias_Current = new Array();
			var column = null;
			for (var i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base
						.trim(layerid).toLowerCase()) {
					arrField_Alias_Current[arrField_Alias_Current.length] = arrField_Alias[i];
				}
			}
			for (var i = 0; i < arrField_Alias_Current.length; i++) {
				if(arrField_Alias_Current[i].IsRequire){
					column = arrField_Alias_Current[i].Name;
					ToolMapAction.columnId = arrField_Alias_Current[i].Name;
					break;
				}
			}
			return column;
		},
		filterFeature:function(masohoso){
			var layerid = null;
			var index = 0;
			var layer = null;
			var column = "";
			var filter = "";
			for(var i=0;i<mapWMS.length;i++){
				layerid = mapWMS[i].LayerId;
				index = mapWMS[i].IndexLayer;
				layer = map.layers[index];
				column = CommonGisBonita.getColumnKey(layerid);
				filter = column+"='"+masohoso+"'";
				layer.mergeNewParams({"CQL_FILTER": filter});
				layer.redraw();	
			}
			for(var i=0;i<mapWFS.length;i++){
				layerid = mapWFS[i].LayerId;
				index = mapWFS[i].IndexLayer;
				layer = map.layers[index];
				column = CommonGisBonita.getColumnKey(layerid);
				var filter = new OpenLayers.Filter.Logical({
				    type: OpenLayers.Filter.Logical.AND,
				    filters: [
				        new OpenLayers.Filter.Comparison({
				            type: OpenLayers.Filter.Comparison.EQUAL_TO,
				            property: column,
				            value: masohoso
				        })
				    ]
				});
				if(layer!=null){
					layer.strategies[2].setFilter(filter);
					layer.refresh({force: true});
	 				layer.redraw(true);
				}
			}
		},
		getTypeAction:function(masohoso,table){
			var column = this.getColumnKey(table);
			$.ajax({
			 	type:"POST",
				url:sPortletJSP+"GetData.jsp",
				data:{
					attr:'gettype',
					mahoso:masohoso,
					tenbang:table,
					column:column
				},
				async:false,
				success:function(data){
					ToolMapAction.typeAction = data.trim();
				}
			});
		}
};

ToolMapAction = {
		typeAction:"",
		isBonita:false,
		indexLayer:0,
		geomType:"",
		drawControl:null,
		sFeatureDel:"",
		index:0,
		typeGeom:"",
		count:0,
		columnId:"",
		layerCurrent:"",
		tbinBonita:"",
		testBonita:function(){
			$("#divDialog_InputTestBonita").dialog("open");
			$("#divDialog_InputTestBonita select").uniform();
		},
		redirectLink:function(){
			var maso = $("#txtMaSoHoSoDemo").val();
			var maloai = $("#selectLayerHoSoDemo").val();
			var layer = $("#selectLayerHoSoDemo option:selected").attr("layerid");
			var appid = $("#selectLayerHoSoDemo option:selected").attr("appid");
			var type = $("#selectTrangThaiDemo").val(); 
			var attr = "?action=frombonita&type="+type+"&masohoso="+maso+"&maloai="+maloai+"&layer="+layer+"&appid="+appid;
			var url = $("#urlPathBonita").val()+attr;
			window.open(url,'_blank');
		},
		callFunction:function(coor,appId,maloai,data,type){
			console.log('coordinate = '+coor);
			$.ajax({
			 	type:"POST",
				url:"/AnGiang-557-portlet/html/commongis/GetData.jsp",
				data:{
					attr:'create_geom',
					coor:coor,
					maloai:maloai,
					dulieu:data,
					appid:appId,
					type:type,
					table:ToolMapAction.layerCurrent,
					geom:ToolMapAction.geomType,
					column:ToolMapAction.columnId
				},
				async:false,
				success:function(data){
					MapAction.RefreshAction();			
					alert(LANGUAGE["msg_save_data_Success"]);
				} 
	 		});
		},
		biddingCombobox:function(){
			var combobox = document.getElementById("selectAssetInsertgeom");
			$(combobox).empty();
			var option = document.createElement('option');
			option.text = LANGUAGE["option_Tool_select_0"];
			option.value = 0;
			combobox.appendChild(option);
			for (var i = 0; i < mapWFS.length; i++) {
				if(mapWFS[i].Display){
					var elOptNew = document.createElement('option');
					elOptNew.text = mapWFS[i].Layer_Name;
					elOptNew.value = mapWFS[i].LayerId;
					combobox.appendChild(elOptNew);				
				}
			}
			$("#selectAssetInsertgeom").uniform();
		},
		bidding:function(layer,mahoso){
			var sHtml = "";
			var objLayer = null;
			for(var i=0;i<vectorArray.length;i++){
				if(vectorArray[i].LayerId==layer){
					if(vectorArray[i].SearchAttr){
						index = vectorArray[i].IndexLayer;
						ToolMapAction.indexLayer = vectorArray[i].IndexLayer;
						ToolMapAction.geomType = vectorArray[i].Geometry_Type;
						ToolMapAction.layerCurrent = vectorArray[i].LayerId;
						break;
					}
				}
			}
			var colname =this.getFieldColumnKey(layer);
			objLayer = map.layers[index];
			$.ajax({
				type : "POST",
				url:"/AnGiang-557-portlet/html/commongis/GetData.jsp",
				async:false,
				data:{
					attr:"get_feature",
					layer:layer,
					mahs:mahoso,
					colum:colname
				},
				success : function(data) {
					var result = data.trim();
					var arrGeom = result.split('<p>');
					var stt=0;
					for(var i=0;i<arrGeom.length;i++){
						var arrFeature = arrGeom[i].split("<g>");
						var splGeom = arrFeature[0].split(";")[1];
						var wkt = new OpenLayers.Format.WKT();
						var features = wkt.read(splGeom);
						var geom1 = features.geometry;
						if(objLayer!=null)objLayer.drawFeature(features,"select");
						stt++;
						if(ToolMapAction.geomType=="point"){//disabled='disabled'
							sHtml+= "<tr>" 
							+"<td><input type='text' id='txtCoorX_"+stt+"' gid='"+arrFeature[1]+"'  value='"+geom1.x+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>"
							+"<td><input type='text' id='txtCoorY_"+stt+"' value='"+geom1.y+"' gid='"+arrFeature[1]+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>"							
							+"<td>" +
									"<img src='/AnGiang-557-portlet/images/delete.png' state='update' gid='"+arrFeature[1]+"' onclick='ToolMapAction.removeCoor(this)'/>" +
									"<img src='/AnGiang-557-portlet/images/zoomToFeatures.png' state='update' id='"+arrFeature[1]+"' onclick='onClickZoomToFeature(this)'/>" +		
									"</td>"							
							+"</tr>";
						}else if(ToolMapAction.geomType=="polygon"){
							var vertices = geom1.getVertices();
							var html1 = "<tr><td colspan='2'><table>";
							var sTable = "";
							for(var j=0;j<vertices.length;j++){
								var x = vertices[j].x;
								var y = vertices[j].y;
								sTable += "<tr><td><input type='text' id='txtCoorX_"+stt+"' gid='"+arrFeature[1]+"' value='"+x+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>" +
								"<td><input type='text' id='txtCoorY_"+stt+"' value='"+y+"' gid='"+arrFeature[1]+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td></tr>";
							}
							sTable+="</table>"								
									+"<td>" +
										"<img src='/AnGiang-557-portlet/images/delete.png' state='update' gid='"+arrFeature[1]+"' onclick='ToolMapAction.removeCoor(this)'/>" +
										"<img src='/AnGiang-557-portlet/images/zoomToFeatures.png' state='update' id='"+arrFeature[1]+"' onclick='onClickZoomToFeature(this)'/>" +
									"</td>" +
								+"</tr>";
							html1+=sTable;
							sHtml+=html1;
						}
					}
				}
			});
			$("#tbody_ListCoor_Bonita").html(sHtml);
		},
		initDraw:function(layer){
			for(var i=0;i<vectorArray.length;i++){
				if(vectorArray[i].LayerId==layer){
					if(vectorArray[i].SearchAttr){
						index = vectorArray[i].IndexLayer;
						ToolMapAction.indexLayer = vectorArray[i].IndexLayer;
						ToolMapAction.geomType = vectorArray[i].Geometry_Type;
						ToolMapAction.layerCurrent = vectorArray[i].LayerId;
						break;
					}
				}
			}
		},
		removeChecked:function(){
			$("#rdoInputCoorClick").removeAttr("checked");
			$("#rdoInputCoorPress").removeAttr("checked");
		},
		getFieldColumnKey:function(layer){
			var i = 0;
			var columName = "";
			var arrAlias = [];
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == layer.toLowerCase()) {
					arrAlias[arrAlias.length] = arrField_Alias[i];
				}
			}
			arrAlias.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});
			
			for(var i=0;i<arrAlias.length;i++){
				if(arrAlias[i].IsPrimaryKey){
					columName = arrAlias[i].Name;
					ToolMapAction.columnId = arrAlias[i].Name;
					break;
				}
			}
			return columName;
		},
		removeCoor:function(ctrl){
			var cf = confirm(LANGUAGE["msg_delete"]);
			if(cf){
				var attr = $(ctrl).attr("gid");
				var state = $(ctrl).attr("state");
				if(ToolMapAction.geomType=="point"){
					if(ToolMapAction.typeAction=="insert"){
						if(ToolMapAction.typeGeom=="click"){
							var feature = vectorGraphics.features[attr];
							vectorGraphics.removeFeatures(feature);
						}
					}else if(ToolMapAction.typeAction=="update"){
						if(state=="update"){
							if(ToolMapAction.sFeatureDel.length==0){
								ToolMapAction.sFeatureDel+=attr;
							}else{
								ToolMapAction.sFeatureDel+=","+attr;
							}
						}
					}
				}else if(ToolMapAction.geomType=="polygon"){
					if(ToolMapAction.typeAction=="insert"){
						if(ToolMapAction.typeGeom=="click"){
							var feature = vectorGraphics.features[attr];
							vectorGraphics.removeFeatures(feature);
						}
					}else if(ToolMapAction.typeAction=="update"){
						if(state=="update"){
							if(ToolMapAction.sFeatureDel.length==0){
								ToolMapAction.sFeatureDel+=attr;
							}else{
								ToolMapAction.sFeatureDel+=","+attr;
							}
						}
					}
				}
				$(ctrl).parent().parent().remove();
			}
		},
		getTypeAction:function(ctrl){
			var type = ctrl.value;
			ToolMapAction.typeGeom = ctrl.value;
			if(type=="click"){
				ToolMapAction.addDrawControl();
				$("#tr_Row_Select_Vertices").hide();
			}else{
				if(ToolMapAction.drawControl!=null){
					ToolMapAction.drawControl.deactivate();
					map.removeControl(ToolMapAction.drawControl);
					ToolMapAction.drawControl = null;
					vectorGraphics.removeAllFeatures();
				}
				if(ToolMapAction.geomType=="point"){
					ToolMapAction.addCoorBonita("","");
					ToolMapAction.removeChecked();
				}else if(ToolMapAction.geomType=="polygon"){
					$("#tr_Row_Select_Vertices").show();
					$("#selectNumberVertices").uniform();
				}
			}
		},
		addCoorBonita:function(coorx,coory){
			var sHTML = $("#tbody_ListCoor_Bonita").html();
			var rows = document.getElementById("tbody_ListCoor_Bonita").rows.length;
			rows = rows+1;
			var sFid = 0;
			if(ToolMapAction.typeGeom=="click")
				sFid = vectorGraphics.features.length;
			else
				sFid = this.count;
			if(ToolMapAction.geomType=="point"){
				sHTML+= "<tr><td><input type='text' id='txtCoorX_"+rows+"' value='"+coorx+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>"
				+"<td><input type='text' id='txtCoorY_"+rows+"' value='"+coory+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>"
				+"<td><img src='/AnGiang-557-portlet/images/delete.png' state='insert' gid='"+sFid+"' onclick='ToolMapAction.removeCoor(this)'/>" +
				"<img src='/AnGiang-557-portlet/images/zoomToFeatures.png' state='update' id='"+sFid+"' onclick='onClickZoomToFeature(this)'/>" +
						"</td>" +
						
				"</tr>";
			}else if(ToolMapAction.geomType=="polygon"){
			}
			$("#tbody_ListCoor_Bonita").html(sHTML);
		},
		addDrawControl:function(){
			if(ToolMapAction.drawControl!=null){
				ToolMapAction.drawControl.deactivate();
				map.removeControl(ToolMapAction.drawControl);
				ToolMapAction.drawControl = null;
			}
			if (ToolMapAction.geomType == Geometries.Point) {
				ToolMapAction.drawControl = new OpenLayers.Control.DrawFeature(
						map.layers[ToolMapAction.indexLayer], OpenLayers.Handler.Point, {
							displayClass : "olControlDrawFeaturePoint",
							title : "Draw point",
							handlerOptions : {
								holeModifier : "altKey"
							}
						});
			}else if (ToolMapAction.geomType == Geometries.Polygon) {
				ToolMapAction.drawControl = new OpenLayers.Control.DrawFeature(
						map.layers[ToolMapAction.indexLayer], OpenLayers.Handler.Polygon,
						{
							displayClass : "olControlDrawFeaturePolygon",
							title : "Draw polygon",
							multi : true,
							handlerOptions : {
								holeModifier : "altKey"
							}
						});
			}
			ToolMapAction.drawControl.events.register('featureadded', ToolMapAction.drawControl, drawFromBonita);
			map.addControl(ToolMapAction.drawControl);
			ToolMapAction.drawControl.activate();
		},
		acceptData:function(){
			var data = $("#txtMaSoHoSo_Bonita").val();
			var maloai = $("#txtMaLoai_Bonita").val();
			var appId = $("#txtAppId_Bonita").val();
			var type = $("#txtType_Bonita").val();
			var sCoor = "";
			var iText = 0;
			var x=0,y=0;
			var sNum = 0;
			var sCoorRs = "";
			var sCoorRsBonita = "";
			var isPoligon = 0;
			INDEX_MODULE = 4;
			if(ToolMapAction.geomType=="point"){
				$("#tbody_ListCoor_Bonita tr").each(function(){
						var objRow = $(this);
						var attr = "";
						$(objRow).find("input[type=text]").each(function(){
							attr = $(this).attr("gid");
							if(iText%2==0){
								x = $(this).val();
								sNum = 0;
							}else{
								y = $(this).val();
								sNum++;
							}
							iText++;
							if(sNum>0){
								if(sCoor.length==0)sCoor=x+" "+y;
								else sCoor+= ";"+x+" "+y;
								if(sCoorRs.length==0)sCoorRs=x+" "+y;
								else sCoorRs +=","+x+" "+y;
							}
						});
						sCoorRsBonita = sCoorRs;
						var state = "";
						var ind = 0;
						$(objRow).find("img").each(function(){
							ind++;
							if(ind == 1)
							state = $(this).attr('state');
						});
						sCoor +="<state>"+state+"<state>"+attr;
				});
			}else if(ToolMapAction.geomType=="polygon"){
				
				isPoligon = 1;
				var childs = $("#tbody_ListCoor_Bonita").children();
				for(var i=0;i<childs.length;i++){
					var objRow = childs[i];
					$(objRow).find("table").each(function(){
						var objTable = $(this);
						sNum = 0,iText = 0;
						var sRow ="";
						var x1=0,y1=0;
						$(objTable).find("input[type=text]").each(function(){
								if(iText%2==0){
									x1 = $(this).val();
									sNum = 0;
								}else{
									y1 = $(this).val();
									sNum++;
								}
								iText++;
								if(sNum>0){
									if(sRow.length==0)sRow=x1+" "+y1;
									else sRow+= ","+x1+" "+y1;
								}
						});
						if(sCoor.length==0)sCoor+=sRow;
						else sCoor+=";"+sRow;
						if(sCoorRs.length==0){ 
							sCoorRs=sRow;
							sCoorRsBonita = sCoorRs;
						}
						else {
							sCoorRs +=sRow;
							sCoorRsBonita += "|" + sRow;
						}
					});
					var attr = "",state="";
					$(objRow).find("img").each(function(){
						attr = $(this).attr("gid");
						state = $(this).attr("state");
					});
					sCoor +="<state>"+state+"<state>"+attr;
				}
			}
			if(type=="update")sCoor+="<del>"+ToolMapAction.sFeatureDel;
			vectorGraphics.removeAllFeatures();
			$("#txtCoordinate").val(sCoorRs);
			this.callFunction(sCoor, appId, maloai, data, type);
			//get table to Bonita
			this.tbinBonita ="<table border= \"1px solid black\" style=\"width: 100%;border-collapse: collapse;\">";
			this.tbinBonita +="  <tr>";
			this.tbinBonita +="    <th style='width:10%'></th>";
			this.tbinBonita +="    <th>" + LANGUAGE["coorx"] + "</th>";
			this.tbinBonita +="    <th>" + LANGUAGE["coory"] + "</th>";
			this.tbinBonita +="  </tr>";
			if(isPoligon == 0){
				var scoor = sCoorRs.split(",");
				for(i = 0; i< scoor.length; i++){
					var coor = scoor[i].split(" ");
					this.tbinBonita +="  <tr>";
					this.tbinBonita +="    <td>A"+ (i+1) +"</td>";
					this.tbinBonita +="    <td style='text-align: center;'>"+ coor[0] +"</td>";
					this.tbinBonita +="    <td style='text-align: center;'>"+ coor[1] +"</td>";
					this.tbinBonita +="  </tr>";
				}
			}else {
				var scoorBonita = sCoorRsBonita.split("|");
				for(var j = 0; j< scoorBonita.length; j++){
					var scoor = scoorBonita[j].split(",");
					for(i = 0; i< scoor.length; i++){
						var row = "";
						var coor = scoor[i].split(" ");
						row +="    <td style='text-align: center;'>"+ coor[0] +"</td>";
						row +="    <td style='text-align: center;'>"+ coor[1] +"</td>";
						this.tbinBonita +="  <tr>";
						if(i==0){
							this.tbinBonita += "    <td rowspan='" + scoor.length + "'>A"+ (j+1) +"</td>";
							this.tbinBonita += row;
						}
						else {
							this.tbinBonita += row;
						}
						this.tbinBonita +="  </tr>";
					}
				}
			}
			this.tbinBonita +="</table>";
			//document.cookie = "tbBonita=" + this.tbinBonita + ";";
			createCookie("tbBonita",this.tbinBonita, 7);
			parent.postMessage(this.tbinBonita, "*");
		}
		,KetThuc: function(){
			alert("a=" + readCookie("tbBonita"));
			parent.postMessage(this.tbinBonita, "*");
		}
};

function drawFromBonita(evt){
	map.layers[ToolMapAction.indexLayer].drawFeature(evt.feature,"select");
	if (ToolMapAction.geomType == Geometries.Point) {
		createPoint(vectorGraphics, evt.feature.geometry);
		var x = evt.feature.geometry.x;
		var y = evt.feature.geometry.y;
		ToolMapAction.addCoorBonita(x,y);
	}else if (ToolMapAction.geomType == Geometries.Polygon) {
		createPolygonFromGeometry(vectorGraphics, evt.feature.geometry);
		var vertices = evt.feature.geometry.getVertices();
		ToolMapAction.index = vertices.length;
		var sHTML = $("#tbody_ListCoor_Bonita").html();
		var sFid = vectorGraphics.features.length;
		var html1 = "<tr><td colspan='2'><table>";
		var sTable = "";
		for(var i=0;i<vertices.length;i++){
			var x = vertices[i].x;
			var y = vertices[i].y;
			sTable += "<tr><td><input type='text' id='txtCoorX_"+i+"' disabled='disabled' value='"+x+"' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>" +
			"<td><input type='text' id='txtCoorY_"+i+"' value='"+y+"' disabled='disabled' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td></tr>";
		}
		sTable+="</table><td>" +
				"<img src='/AnGiang-557-portlet/images/delete.png' state='insert' gid='"+sFid+"' onclick='ToolMapAction.removeCoor(this)'/>" +
				"<img src='/AnGiang-557-portlet/images/zoomToFeatures.png' state='insert' id='"+sFid+"' onclick='onClickZoomToFeature(this)'/>" +
						"</td></tr>";
		html1+=sTable;
		$("#tbody_ListCoor_Bonita").html(sHTML+html1);
	}
}
function getNumberVertices(ctrl){
	var num = ctrl.value;
	var sHTML = $("#tbody_ListCoor_Bonita").html();
	ToolMapAction.count++;
	var rows = document.getElementById("tbody_ListCoor_Bonita").rows.length;
	rows = rows+1;
	var html1 = "<tr><td colspan='2'><table>";
	var sTable = "";
	for(var i=0;i<num;i++){
		sTable += "<tr><td><input type='text' id='txtCoorX_"+i+"' value='' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/></td>" +
		"<td><input type='text' id='txtCoorY_"+i+"' value='' class='checknumber' onkeydown='txtKeyDownHoSo(event)'/>";
	}
	sTable+="</table></td><td rowspan='"+num+"'>" +
			"<img src='/AnGiang-557-portlet/images/delete.png' gid='"+ToolMapAction.count+"' onclick='ToolMapAction.removeCoor(this)'/>" +
			"<img src='/AnGiang-557-portlet/images/zoomToFeatures.png' state='update' id='"+ToolMapAction.count+"' onclick='onClickZoomToFeature(this)'/>" +
					"</td></tr>";
	html1+=sTable;
	$("#tbody_ListCoor_Bonita").html(sHTML);
}

function getNumberVertices123(ctrl){
	var num = ctrl.value;
	for(var i=0;i<num;i++){
		var trCoor = document.getElementById("trCoor_khaithac_"+i);
		if(trCoor!=null)$(trCoor).remove();
	}
	arrInputCoor = [];
	var trSelect = document.getElementById("trSelectPolygon_KhaiThac");
	var count = 0;
	for(var i=0;i<num;i++){
		var objTR = document.createElement("tr");
		objTR.id = "trCoor_khaithac_"+i;
		count++;
		var tdX = document.createElement("td");
		tdX.innerHTML = LANGUAGE["coorx"]+count;
		var tdInputX = document.createElement("td");
		var inputX = document.createElement("input");
		var divX = document.createElement("div");
		divX.setAttribute("class","input input-mdf wd-s1");
		inputX.type="text";
		inputX.id = "txtCoorX_KhaiThac_"+i;
		inputX.onkeydown = txtKeyDownHoSo;
		divX.appendChild(inputX);
		tdInputX.appendChild(divX);
		arrInputCoor.push("#txtCoorX_KhaiThac_"+i);
		var tdY = document.createElement("td");
		tdY.innerHTML = LANGUAGE["coory"]+count;
		var tdInputY = document.createElement("td");
		var inputY = document.createElement("input");
		var divY = document.createElement("div");
		divY.setAttribute("class","input input-mdf wd-s1");
		inputY.type="text";
		inputY.id = "txtCoorY_KhaiThac_"+i;
		inputY.onkeydown = txtKeyDownHoSo;
		divY.appendChild(inputY);
		tdInputY.appendChild(divY);
		arrInputCoor.push("#txtCoorY_KhaiThac_"+i);
		
		objTR.appendChild(tdX);
		objTR.appendChild(tdInputX);
		objTR.appendChild(tdY);
		objTR.appendChild(tdInputY);
		trSelect.parentNode.insertBefore(objTR, trSelect);
	}	
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
